package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/10 16:03
 * @description
 */
public class Code119 {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> result = new ArrayList<>();
        result.add(Collections.singletonList(1));
        if (rowIndex == 0) {
            return result.get(rowIndex);
        }
        result.add(Arrays.asList(1, 1));
        if (rowIndex == 1) {
            return result.get(rowIndex);
        }
        for (int i = 2; i < rowIndex; i++) {
            List<Integer> r = new ArrayList<>();
            r.add(1);
            List<Integer> preResult = result.get(i - 1);
            for (int j = 0; j < preResult.size() - 1; j++) {
                r.add(preResult.get(j) + preResult.get(j + 1));
            }
            r.add(1);
            result.add(r);
        }
        return result.get(rowIndex);
    }
}
